import {
  createSlice,
  configureStore
} from '@reduxjs/toolkit';

//创建共享数据模块
const publicModule = createSlice({
  //必须填写, 模块名称
  name: 'publicModule',

  //公共数据
  initialState: {
    //购物袋总数量
    count: 0,

    //是否请求过购物袋数量
    isLoadShopbagCount: false
  },

  reducers: {
    //修改购物袋数量
    changeCount(state, action) {
      state.count = action.payload;
    },

    //修改isLoadShopbagCount
    changeIsLoadShopbagCount(state, action) {
      state.isLoadShopbagCount = action.payload;
    }
  }
})

//导出reducers的方法
export const {changeCount, changeIsLoadShopbagCount} = publicModule.actions;

//导出共享数据模块
export default configureStore({
  reducer: {
    publicModule: publicModule.reducer
  }
})